package com.wanxi.service.Impl;

import com.wanxi.dao.CompanyDao;
import com.wanxi.dao.Impl.CompanyDaoImpl;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.CompanyModel;
import com.wanxi.service.CompanyService;

/**
 * @author Li
 * @Date 2023/5/6 14:21
 */
public class CompanyServiceImpl implements CompanyService {
    private   CompanyDao companyDao = new CompanyDaoImpl();
    public ResultDto add(CompanyModel companyModel) {

        boolean same = companyDao.findSameName(companyModel);
        if (same){
            return ResultDto.builder()
                    .code(0)
                    .msg("用户名已存在")
                    .build();
        }
        return ResultDto.builder()
                .code(0)
                .msg("添加成功")
                .count(companyDao.add(companyModel))
                .build();
    }

    public ResultDto update(CompanyModel companyModel) {

//        boolean same = companyDao.findSameName(companyModel);
//        if (same){
//            return ResultDto.builder()
//                    .code(0)
//                    .msg("用户名已存在")
//                    .build();
//        }
        return ResultDto.builder()
                .code(0)
                .msg("修改成功")
                .count(companyDao.update(companyModel))
                .build();
    }

    public ResultDto delete(CompanyModel companyModel) {

        return ResultDto.builder()
                .code(0)
                .msg("删除成功")
                .count(companyDao.delete(companyModel))
                .build();
    }

    public ResultDto findAll(CompanyModel companyModel) {

        return ResultDto.builder()
                .code(0)
                .msg("查询成功")
                .count(companyDao.count(companyModel))
                .data(companyDao.findAll(companyModel))
                .build();
    }

    public ResultDto findById(CompanyModel companyModel) {
        return ResultDto.builder()
                .code(0)
                .msg("查询成功")
                .data(companyDao.findById(companyModel))
                .build();
    }

    @Override
    public Integer totalCount() {
        return null;
    }
}
